public class LeetCode1456 {

    public static void main(String[] args) {
        LeetCode1456 leetCode1456 = new LeetCode1456();
        System.out.println(leetCode1456.maxVowels("abciiidef", 3));
    }

    public int maxVowels(String s, int k) {
        int max = 0;
        int current = 0;
        char[] data = s.toCharArray();
        int length = s.length();
        for(int startIndex = 0; startIndex < k; startIndex++){
            if(hasAeiou(data[startIndex])){
                current++;
            }
        }

        max = current;
        for(int index = k; index <length; index++){
            if(hasAeiou(data[index - k])){
                current --;
            }

            if(hasAeiou(data[index])){
                current++;
            }

            if(current > max){
                max = current;
            }
        }
        return max;
    }

    char[] AEIOU = new char[]{'a','e','i','o','u'};
    public boolean hasAeiou(char element){
        for(char ch : AEIOU){
            if(ch == element){
                return true;
            }
        }
        return false;
    }

    public int maxVowels2(String s, int k) {
        int max = 0;
        int current = 0;
//        char[] data = s.toCharArray();
        for(int startIndex = 0; startIndex < k; startIndex++){
            if(hasAeiou(s.charAt(startIndex))){
                current++;
            }
        }

        max = current;
        for(int index = k; index <s.length(); index++){
            if(hasAeiou(s.charAt(index - k))){
                current --;
            }

            if(hasAeiou(s.charAt(index))){
                current++;
            }

            if(current > max){
                max = current;
            }
        }
        return max;
    }
}
